package edu.gatech.teamrocket;

import com.j256.ormlite.android.apptools.OpenHelperManager;
import edu.gatech.teamrocket.models.*;

import android.app.Application;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class DewApplication extends Application {
	private volatile DatabaseHelper databaseHelper = null;
	private volatile Auth auth = null;
	private SharedPreferences settings;
	
	public void onCreate() {
		settings = PreferenceManager.getDefaultSharedPreferences(this); // get the shared preferences
	}
	
	/**
	 * Retrieves the SharedPreferences for the app.
	 * @return settings
	 */
	public SharedPreferences getSettings() {
		return settings;
	}
    
	/**
	 * Retrieves the DatabaseHelper for ORMLite.
	 * @return DatabaseHelper instance
	 */
	public DatabaseHelper getHelper() {
    	if (databaseHelper == null) {
    		databaseHelper = OpenHelperManager.getHelper(this, DatabaseHelper.class);
    	}
    	return databaseHelper;
	}
	
	/**
	 * Retrieves the Auth class.
	 * @return Auth instance
	 */
	public Auth getAuth() {
		if (auth == null) {
			auth = Auth.getInstance(this);
		}
		
		return auth;
	}
}